#ifndef SINGLETON_H
#define SINGLETON_H

#ifdef _DEBUG
    #include <cassert>
#endif // _DEBUG

template <typename T> class Singleton
{
private:
    static T *m_Singleton;

public:
    Singleton()
    {
    #ifdef _DEBUG
        assert(m_Singleton == NULL);
    #endif /* _DEBUG */
        m_Singleton = (T *)((int) this + ((int)(T *) 1 - (int)(Singleton <T> *)(T *) 1));
    }

    ~Singleton()
    {
    #ifdef _DEBUG
        assert(m_Singleton != NULL);
    #endif /* _DEBUG */
        m_Singleton = NULL;
    }

    static T &GetObj()																	{ return *m_Singleton; }
    static T *GetPtr()																	{ return m_Singleton; }
};

template <typename T> T *Singleton <T>::m_Singleton = NULL;

#endif // SINGLETON_H
